package idv.takeshi.software.productline.bookstore.domain.model.order;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * A model class as a payment to indicate that it shall be paid by postal order.
 * @author takeshi
 *
 */
@Entity
@Table(name = "POSTAL_ORDER")
public class PostalOrder extends BeforeDeliveryPayment {
	
	@Column(length = 30, name = "RECEIVER_NAME")
	private String receiverName;
	@Column(length = 30, name = "PAYER_NAME") 
	private String payerName;
	@Column(length = 100, name = "ADDRESS") 
	private String address;
	@Column(length = 20, name = "PHONE_NO") 
	private String phoneNumber;
	@Column(length = 3, name = "DEPOSIT_BANK_ID")
	private String depositForBankId;
	@Column(length = 16, name = "DEPOSIT_ACCOUNT_NO") 
	private String depositForAccountNumber;

	/**
	 * @return the receiverName
	 */
	public String getReceiverName() {
		return receiverName;
	}

	/**
	 * @param receiverName the receiverName to set
	 */
	public void setReceiverName(String receiverName) {
		this.receiverName = receiverName;
	}

	/**
	 * @return the payerName
	 */
	public String getPayerName() {
		return payerName;
	}

	/**
	 * @param payerName the payerName to set
	 */
	public void setPayerName(String payerName) {
		this.payerName = payerName;
	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the phoneNumber
	 */
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @param phoneNumber the phoneNumber to set
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	/**
	 * @return the depositForBankId
	 */
	public String getDepositForBankId() {
		return depositForBankId;
	}

	/**
	 * @param depositForBankId the depositForAccountId to set
	 */
	public void setDepositForBankId(String depositForBankId) {
		this.depositForBankId = depositForBankId;
	}

	/**
	 * @return the depositForAccountNumber
	 */
	public String getDepositForAccountNumber() {
		return depositForAccountNumber;
	}

	/**
	 * @param depositForAccountNumber the depositForAccountNumber to set
	 */
	public void setDepositForAccountNumber(String depositForAccountNumber) {
		this.depositForAccountNumber = depositForAccountNumber;
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.domain.model.order.Payment#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (!(obj instanceof PostalOrder)) {
		     return false;
		   }
		   PostalOrder rhs = (PostalOrder) obj;
		   return new EqualsBuilder()
		   	   .appendSuper(super.equals(rhs))
			   .append(this.payerName, rhs.payerName)
			   .append(this.receiverName, rhs.receiverName)
			   .append(this.address, rhs.address)
			   .append(this.phoneNumber, rhs.phoneNumber)
			   .append(this.depositForBankId, rhs.depositForBankId)
			   .append(this.depositForAccountNumber, rhs.depositForAccountNumber)
		       .isEquals();
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.domain.model.order.Payment#hashCode()
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(31, 79).
		   appendSuper(super.hashCode()).
	       append(this.payerName).
	       append(this.receiverName).
	       append(this.address).
	       append(this.phoneNumber).
	       append(this.depositForBankId).
	       append(this.depositForAccountNumber).
	       toHashCode();
	}
	 
}
 
